package pack1_Singleton;
/*
 * 饿汉式单例模式：static修饰的emperor属于类成员变量，final修饰的emperor是一个常量，因此线程是安全
 */

class Emperor1{
    private static final Emperor1 emperor = new Emperor1();
    private Emperor1(){};
    public static Emperor1 getInstance(){
        return emperor;
    }
}

class Minister1{
    private Emperor1 emperor = Emperor1.getInstance(); 
    public Emperor1 getEmperor(){
        return this.emperor;
    }
}

public class code001_hungrySingleton{

    public static void main(String[] args) {
        Minister1 m1 = new Minister1();
        Minister1 m2 = new Minister1();

        System.out.println(m1.getEmperor() == m2.getEmperor());
    }
}